package redis;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;

import org.redisson.Config;
import org.redisson.Redisson;  
/**
 * 简单点的redis样例
 * @author ytu
 *
 */
public class Redis_Simple_Example {  
  
    /** 
     * @param args 
     */  
    public static void main(String[] args) {  
        // 1.初始化  
        Config config = new Config();  
//        config.setConnectionPoolSize(10);
        config.setThreads(10);
        config.useSingleServer().setAddress("192.168.247.129:6379");  
        Redisson redisson = Redisson.create(config);  
        System.out.println("reids连接成功...");  
  
        // 2.测试concurrentMap,put方法的时候就会同步到redis中  
        ConcurrentMap<String, Object> map = redisson.getMap("FirstMap");  
        map.put("yetongxue", "男");  
        map.put("zhangbin", "男");  
        map.put("lili", "女");  
  
        ConcurrentMap resultMap = redisson.getMap("FirstMap");  
        System.out.println("resultMap==" + resultMap.keySet());  
  
        // 2.测试Set集合  
        Set mySet = redisson.getSet("MySet");  
        mySet.add("zhangbin");  
        mySet.add("lili");  
  
        Set resultSet = redisson.getSet("MySet");  
        System.out.println("resultSet===" + resultSet.size());  
          
        //3.测试Queue队列  
        Queue myQueue = redisson.getQueue("FirstQueue");  
        myQueue.add("yetongxue");  
        myQueue.add("lili");  
        myQueue.add("zhangbin");  
        myQueue.peek();  
        myQueue.poll();  
  
        Queue resultQueue=redisson.getQueue("FirstQueue");  
        System.out.println("resultQueue==="+resultQueue);  
          
        // 关闭连接  
        redisson.shutdown();  
    }  
  
} 